package com.example.yuanann.vegetable_app.repository.dao;

import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Transaction;
import androidx.room.Update;

import com.example.yuanann.vegetable_app.repository.entity.User;

import java.util.List;
import java.util.concurrent.Callable;

import io.reactivex.rxjava3.core.Completable;
import io.reactivex.rxjava3.core.Flowable;
import io.reactivex.rxjava3.core.Maybe;
import io.reactivex.rxjava3.core.Single;

@Dao
public interface UserDao {

    @Insert
    Completable insert(User user);

    @Update
    Single<Integer> update(User user);

    @Delete
    Single<Integer> delete(User user);

    @Query(value = "delete from users where user_id = :id")
    Single<Integer> deleteById(Integer id);

    @Query(value = "select user_id,user_name,password,user_type from users where user_id = :id")
    Maybe<User> getOneById(Integer id);

    @Query(value = "select user_id,user_name,password,user_type from users where user_name = :userName and password = :password")
    Maybe<User> getOneByUserNamePassword(String userName, String password);

    @Query(value = "select user_id,user_name,password,user_type from users where user_name = :userName and password = :password and user_type = :userType")
    Maybe<User> getOneByUserNamePasswordUserType(String userName, String password, String userType);

    @Query("select user_id,user_name,password,user_type from users")
    Flowable<List<User>> getAll();
}
